const path = require('path');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
const { merge } = require('webpack-merge');
const { srcPath, distPath } = require('./paths');
// const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin');

module.exports = merge(webpackConfig, {
    mode: 'development',
    devtool: 'source-map',
    module: {
        rules: [
            {
                test: /\.(png|jpe?g|gif|svg)$/,
                loader: 'file-loader'
            },
            {
                test: /\.(woff|eot|ttf)$/,
                loader: 'file-loader'
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader', 'postcss-loader']
            },
            {
                test: /\.less$/,
                use: [
                    'style-loader',
                    'css-loader',
                    {
                        loader: 'less-loader',
                        options: {
                            lessOptions: {
                                javascriptEnabled: true // 当解析antd.less，必须写成下面格式，否则会报Inline JavaScript is not enabled错误
                            }
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        new webpack.DefinePlugin({
            ENV: JSON.stringify('development')
        }),
        new webpack.HotModuleReplacementPlugin(),

        // 后续加入dllplugin
    ],
    target: 'web',
    devServer: {
        host:'localhost',
        port: 8080,
        progress: true,  // 显示打包的进度条
        contentBase: distPath,  // 根目录
        open: true,  // 自动打开浏览器
        compress: true,  // 启动 gzip 压缩
        hot: true,
        historyApiFallback:true,
        // 设置代理
        // proxy: {
        //     // 将本地 /api/xxx 代理到 localhost:3000/api/xxx
        //     '/api': 'http://localhost:3000',

        //     // 将本地 /api2/xxx 代理到 localhost:3000/xxx
        //     '/api2': {
        //         target: 'http://localhost:3000',
        //         pathRewrite: {
        //             '/api2': ''
        //         }
        //     }
        // }
    },
});